//
//  ZZTabBar.m
//  Sina
//
//  Created by 张卓 on 2017/1/16.
//  Copyright © 2017年 ZZ. All rights reserved.
//

#import "ZZTabBar.h"

@interface ZZTabBar()
@property (nonatomic,strong) UIButton *bnt;
@end


@implementation ZZTabBar

- (UIButton *)bnt{
    if (_bnt == nil) {
        _bnt = [[UIButton alloc]init];
    }
    
    return _bnt;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
        [self addSubview:self.bnt];
    }
    return self;
}
- (void)layoutSubviews {
    [super layoutSubviews];
    //获取屏幕的宽度  5个控件
    CGFloat w = self.frame.size.width * 0.2;
    
    //确定控件index
    CGFloat index = 0;
  
    for (UIView *view in self.subviews) {
        if([view isKindOfClass:NSClassFromString(@"UITabBarButton")]){
            //设置宽度 和 x
            CGRect f = view.frame;
            f.size.width = w;
            f.origin.x = index * w;
            view.frame = f;
            index ++;
            if(index == 2){
                index ++;
            }
            
        }
        
    }
    //设置bnt的frame
//    CGRect f = self.frame;
//    self.bnt.center.x  = f.size.width * 0.5;
//    self.bnt.center.y = f.size.height * 0.5;
//
    self.bnt.center = CGPointMake(self.frame.size.width * 0.5, self.frame.size.height * 0.5);
    
}




- (void)setupUI {
    
//    UIButton *bnt= [[UIButton alloc]init];
    [self.bnt setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
    [self.bnt setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
    [self.bnt setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
    [self.bnt setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
    
    [self.bnt sizeToFit];
//    return self.bnt;
}



@end
